package com.moli.iov.gateway.server;

import com.moli.iov.gateway.server.codec.StreamByteDecoder;
import com.moli.iov.gateway.server.codec.StreamByteEncoder;


import com.moli.iov.util.PropertiesUtils;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
/**
 * Server Channel初始化处理接口
 *
 */
public class NettyServerInitializer extends ChannelInitializer<SocketChannel>{
	//server读超时时间(秒)
	private static final  int readerIdleTimeSeconds = Integer.parseInt(PropertiesUtils.getProperty("netty.server.readerIdleTimeSeconds"));//读操作空闲120秒
	//server写超时时间(秒)
	private static final  int writerIdleTimeSeconds = Integer.parseInt(PropertiesUtils.getProperty("netty.server.writerIdleTimeSeconds"));//写操作空闲120秒
	//server读写超时时间(秒)
	private static final  int allIdleTimeSeconds = Integer.parseInt(PropertiesUtils.getProperty("netty.server.allIdleTimeSeconds"));//读写全部空闲180秒
	
	
	public NettyServerInitializer(){
	}
	
	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();
		pipeline.addLast(new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds));
		pipeline.addLast(new StreamByteEncoder());  
		pipeline.addLast(new StreamByteDecoder());  
		pipeline.addLast(new NettyServerHandler());
	}

}
